$(function() {
	if ($("#typeClass").val() == 1) {
		$("#aCalss").html("修改友情链接");
		$.post("findFriendyLinksById.do?id=" + $("#fIdClass").val(), function(
				data) {
			$("#linkName").val(data.data[0].fName);
			$("#linkAddress").val(data.data[0].fPath);
		}, "json")
	}
})
layui.use('form', function() {
	var form = layui.form;
	//监听提交
	form.on('submit(formDemo)', function(data) {
		if ($("#typeClass").val() == 1) {
			$.post("FriendshipLinkUpdate.do", {
				linkName : data.field.linkName,
				linkAddress : data.field.linkAddress,
				id : $("#fIdClass").val()
			}, function(res) {
				if (res.type == 1) {
					layer.alert("修改成功", {
						icon : 6
					}, function() {
						// 获得frame索引
						window.parent.location.reload();
						var index = parent.layer.getFrameIndex(window.name);
						//关闭当前frame
						window.location.reload();
						parent.layer.close(index);
					});
				} else {
					layer.msg("修改失败", {
						area : [ '300px', '200px' ]
					});
					setTimeout(function() {
						//刷新
						location.reload();
					}, 1000);
				}
			}, "json")
		} else {
			$.post("FriendshipLinkInsert.do", {
				linkName : data.field.linkName,
				linkAddress : data.field.linkAddress
			}, function(res) {
				if (res.type == 1) {
					layer.alert("添加成功", {
						icon : 6
					}, function() {
						// 获得frame索引
						var index = parent.layer.getFrameIndex(window.name);
						//关闭当前frame
						parent.layer.close(index);
						window.location.reload();
					});
				} else {
					layer.msg("添加失败", {
						area : [ '300px', '200px' ]
					});
					setTimeout(function() {
						//刷新
						location.reload();
					}, 1000);
				}
			}, "json")
		}

		return false;
	});
});